<?php
/**
 * 微信支付接口类
 *
 * 
 * @copyright  Copyright (c) 2007-2014 ShopNC Inc. (http://www.shopnc.net)
 * @license    http://www.shopnc.net
 * @link       http://www.shopnc.net
 * @since      File available since Release v1.1
 */
defined('InShopNC') or exit('Access Invalid!');
require_once "lib/WxPay.Api.php";
require_once "WxPay.Config.php";
class wxpay{

    public function __construct(){}

    public function refundOrder($order_info,$refund){
    	$result = array();
    	try{
    		//echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
			//微信订单号
    		$transaction_id = $order_info["trade_no"];
    		//订单金额(单位为分，只能为整数)
			$total_fee = $order_info["order_amount"]*100;
			//退款金额(单位为分，只能为整数)
    		$refund_fee = $refund["refund_amount"]*100;
			//商户订单号(微信订单号和商户订单号二选一) 不过好像必须要用微信订单号
    		$out_trade_no = $order_info["pay_sn"];
    		$input = new WxPayRefund();
    		$input->SetTransaction_id($transaction_id);
    		$input->SetTotal_fee($total_fee);
    		$input->SetRefund_fee($refund_fee);
    		$input->SetOut_trade_no($out_trade_no);
    	
    		$config = new WxPayConfig();
    		$input->SetOut_refund_no("sdkphp".date("YmdHis"));
    		$input->SetOp_user_id($config->GetMerchantId());
    		$result = WxPayApi::refund($config, $input);
    	} catch(Exception $e) {
    		$result['result_code'] = 'FAIL';
    		$result['err_code_des'] = '微信退款失败';
    	}
    	return $result;
    }
}
